package com.luzhikun.Filter;

import javax.servlet.*;
import javax.servlet.annotation.*;
import java.io.IOException;
/*
 * @Author liu-miss
 * @Description 拦截所有的请求，并改变字符集
 * @Date 8:47 2021/5/8
 **/

@WebFilter(filterName = "CharsetFilter",value = "/*")
public class CharsetFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        // 设置请求对象的字符集为UTF-8
        request.setCharacterEncoding("UTF-8");
        // 放行
        chain.doFilter(request,response);

    }

    @Override
    public void destroy() {

    }
}
